#ifndef PERFORMANCE_TIMER_H
#define PERFORMANCE_TIMER_H

#include <string>
#include <chrono>
#include <limits>
#include <unordered_map>
#include <memory>
#include <iostream>

class Timer {
public:
    explicit Timer(const std::string& name);

    void start();
    void end();
    void printSummary() const;

    std::string getName() const;
    int getCount() const;
    double getMinDuration() const;
    double getMaxDuration() const;
    double getAvgDuration() const;

private:
    std::string name;
    int count;
    double total_duration;
    double min_duration;
    double max_duration;
    std::chrono::high_resolution_clock::time_point start_time;
};

class TimerManager {
public:
    static TimerManager& getInstance();

    void start(const std::string& name);
    void end(const std::string& name);
    void printAllSummaries() const;

    std::shared_ptr<Timer> getTimer(const std::string& name);
    std::shared_ptr<Timer> getOrCreateTimer(const std::string& name);

private:
    TimerManager() = default;
    std::unordered_map<std::string, std::shared_ptr<Timer>> timers;
};

#endif // PERFORMANCE_TIMER_H
